package com.example.config.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

//@WebServlet(name = "myServlet", urlPatterns = "/api/my/servlet", initParams = {
//        @WebInitParam(name = "name", value = "chengxumiao"),
//        @WebInitParam(name = "website", value = "http://www.ibloger.net")
//})
public class MyServlet extends HttpServlet {

    private String name;
    private String website;

    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("------ 初始化 myServlet ------");
        this.name = config.getInitParameter("name");
        this.website = config.getInitParameter("website");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out = resp.getWriter();
        out.println("name: " + name + ", website: " + website);
        out.flush();
        out.close();
    }

}
